<?php
/** [字段控制器]
 * @Author: 976123967@qq.com
 * @Date:   2015-01-09 16:59:21
 * @Last Modified by:   Administrator
 * @Last Modified time: 2015-01-15 13:51:02
 */
class FieldAction extends PublicAction{

	public $logic;
	public $getMid;
	public $postMid;
	public function _initialize()
	{
		parent::_initialize();
		$this->logic   = D('Field','Logic');

		$this->getMid  = I('get.mid');
		$this->postMid = I('post.mid');

		if(!$this->getMid && !$this->postMid )
		{
			$this->error('链接错误');
		}
	}

	/**
	 * [index 字段列表]
	 * @return [type] [description]
	 */
	public function index()
	{
	
		$logic =D('Model','Logic')->get_all();
		$this->assign('modelRemark',$logic[$this->getMid]['remark']);

		$data  = $this->logic->get_all_by_model_mid($this->getMid);
		$this->assign('data',$data);
		$this->display();
	}

	/**
	 * [operation 更新字段操作]
	 * @return [type] [description]
	 */
	public function operation()
	{
		if(!$msg = $this->logic->operation())
			$this->error($this->logic->getError());
		$this->success($msg,U('Field/index',array('mid'=>$this->postMid)));
	}

	/**
	 * [update_cache 更新缓存]
	 * @return [type] [description]
	 */
	public function update_cache()
	{
		$this->logic->update_cache();
		$this->success('缓存更新成功',U('Field/index',array('mid'=>$this->getMid)));
	}


	/**
	 * [add 添加]
	 */
	public function add()
	{
		if(IS_POST)
		{
			if(!$this->logic->add_field())
				$this->error($this->logic->getError());
			$this->success('字段添加成功',U('Field/index',array('mid'=>$this->postMid)));
			die;
		}
		$logic =D('Model','Logic')->get_all();
		$this->assign('modelRemark',$logic[$this->getMid]['remark']);
		$this->display();
	}



	/**
	 * [edit 编辑]
	 * @return [type] [description]
	 */
	public function edit()
	{


		if(IS_POST)
		{
			if(!$this->logic->update_field())
				$this->error($this->logic->getError());
			$this->success('字段修改成功',U('Field/index',array('mid'=>$this->postMid)));
			die;
		}


		// 读取数据
		$field = $this->logic->find_one();
		if(!$field) 
			$this->error($this->logic->getError());
		$this->assign('field',$field);

		$logic = D('Model','Logic')->get_all();
		$this->assign('modelRemark',$logic[$this->getMid]['remark']);
		$this->display();
	}

	/**
	 * [del 删除]
	 * @return [type] [description]
	 */
	public function del()
	{
		if(!$this->logic->del_field())
			$this->error($this->logic->getError());
		$this->success('字段删除成功',U('Field/index',array('mid'=>$this->getMid)));
	}

}